/******************************************************************************
 * @File name   :      DealerInfoSyncDaoImpl.java
 *
 * @Author      :      GUDONG
 *
 * @Date        :      2015年10月14日
 *
 * @Copyright Notice: 
 * Copyright (c) 2014 Capgemini, Inc. All  Rights Reserved.
 * This software is published under the terms of the Capgemini Software
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 * 
 * 
 * ----------------------------------------------------------------------------
 * Date                   Who         Version        Comments
 * 2015年10月14日 下午5:33:49        GUDONG     1.0            Initial Version
 *****************************************************************************/
package com.cap.bts.crmdp.dealer.dealerinfosync.dao.impl;

import java.util.List;

import javax.inject.Inject;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;

import com.cap.bts.crmdp.dealer.dealerinfosync.dao.IDealerInfoSyncDao;
import com.cap.bts.crmdp.dealer.dealerinfosync.domain.DealerInfoRelMars;
import com.cap.bts.framework.common.dao.callback.NativeQueryBySqlJpaCallback;
import com.cap.bts.framework.common.dao.impl.BaseDaoImpl;
import com.cap.bts.framework.common.exception.AppException;

/**
 *
 */
@Repository("dealerInfoSyncDao")
public class DealerInfoSyncDaoImpl extends BaseDaoImpl<DealerInfoRelMars, Long> implements IDealerInfoSyncDao {

    /**
     * @Date        :      2015年10月14日
     * @param clazz
     */
    @Inject
    public DealerInfoSyncDaoImpl(@Value("com.cap.bts.crmdp.dealer.dealerinfosync.domain.DealerInfoRelMars") Class<DealerInfoRelMars> clazz) {
        super(clazz);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年10月14日
     * @see com.cap.bts.crmdp.dealer.dealerinfosync.dao.IDealerInfoSyncDao#deleteDealerInfoSync()
    **/
    @Override
    public void deleteDealerInfoSync() throws AppException {
        String sql = "delete from DealerInfoRelMars";
        this.removeByQuery(sql);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月18日
     * @see com.cap.bts.crmdp.dealer.dealerinfosync.dao.IDealerInfoSyncDao#getMarsTenantIdByDealerId(java.lang.Long)
    **/
    @Override
    public List<DealerInfoRelMars> getMarsTenantIdByDealerId(Long dealerId) throws AppException {
        String sql = "select * from tm_dealer_rel_mars where dealer_id = " + dealerId;
        return this.getListByNativeQuery(sql);
    }

    /**
     * {@inheritDoc} 
     * overridden:
     * @Date        :      2015年11月18日
     * @see com.cap.bts.crmdp.dealer.dealerinfosync.dao.IDealerInfoSyncDao#getDealerIdByMarsTenantId(java.lang.Long)
    **/
    @Override
    public List<Integer> getDealerIdByMarsTenantId(String marsTenantId) throws AppException {
        String sql = "select dealer_id from tm_dealer_rel_mars where mars_tenant_id = '" + marsTenantId + "'";
        return this.getJpaTemplate().executeFind(new NativeQueryBySqlJpaCallback<Integer>(sql));
    }

}
